package cn.cuilan.controller;

import cn.cuilan.service.BookClasifyService;
import cn.cuilan.utils.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 书籍分类
 *
 * @author zhang.yan
 */
@RestController
@RequestMapping("/bookclassify")
public class BookClassifyController {

    private final BookClasifyService bookClasifyService;

    @Autowired
    public BookClassifyController(BookClasifyService bookClasifyService) {
        this.bookClasifyService = bookClasifyService;
    }

    /**
     * 根据 id 查询
     *
     * @param id s书籍分类id
     * @return 返回书籍对象
     */
    @RequestMapping(value = "/findById", method = RequestMethod.GET)
    public Results findById(long id) {
        return Results.success().data(bookClasifyService.findById(id));
    }

    /**
     * 查询所有书籍分类、根据分类名称模糊查询
     *
     * @param classifyName 书籍分类名称
     * @return 返回list
     */
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public Results findAll(@RequestParam(value = "classifyName", required = false) String classifyName) {
        return Results.success().data(bookClasifyService.finAllBookClassify(classifyName));
    }

}
